package com.rijndael;


import javax.crypto.Cipher;
import javax.crypto.spec.IvParameterSpec;
import javax.crypto.spec.SecretKeySpec;

import org.apache.commons.codec.binary.Base64;

/**
 * 此处使用AES-128-CBC加密模式，key需要为16位
 * 
 * 由于不稳定，暂时处理一下
 * 
 * @author Administrator
 *
 */
public class AES4 {

	// 加密   
    public static String encrypt(String sSrc) throws Exception {   
        return Base64.encodeBase64String(sSrc.getBytes());//此处使用BAES64做转码功能，同时能起到2次加密的作用。   
    }   
   
    // 解密   
    public static String decrypt(String sSrc) throws Exception {   
        try {   
        	
            byte[] encrypted1 = Base64.decodeBase64(sSrc);//先用bAES64解密   
            try {   
                String originalString = new String(encrypted1);   
                return originalString;   
            } catch (Exception e) {   
                System.out.println(e.toString());   
                return null;   
            }   
        } catch (Exception ex) {   
            System.out.println(ex.toString());   
            return null;   
        }   
    }   
    
    public static void main(String[] args) throws Exception {
		/*String en = AES3.encrypt("wewrw2/678dfgdterreterterttedfgdgdfgdfrt4e56t46er5464rte654ter5er主键wer");
		System.out.println("encoder is : "+en);*/
		String test = "d2V3cncyLzY3OGRmZ2R0ZXJyZXRlcnRlcnR0ZWRmZ2RnZGZnZGZydDRlNTZ0NDZlcjU0NjRydGU2NTR0ZXI1ZXLkuLvplK53ZXI=";
		System.out.println(AES4.decrypt(test));
	}

}
